package strategy.pattern.demo;

import choices.FirstChoice;
import choices.IChoice;
import choices.SecondChoice;
import contextofchoice.Context;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Created by DELL
 * Date: 2019/9/29.
 * Time: 14:20
 */
public class StrategyPatternEx {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        IChoice ic;
        Context context = new Context();
        String input1, input2;
        try {
            for (int i = 1; i <= 2; i++) {
                System.out.println("Enter an Integer:");
                input1 = in.nextLine();
                System.out.println("Enter an Integer:");
                input2 = in.nextLine();
                System.out.println("Enter ur choice(1 or 2)");
                System.out.println("Press 1 for Addition, 32 for Concatenation");
                String c = in.nextLine();
                /* For java old version is-use these lines to collect input from user
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String c1 = br.readLine();*/
                if (c.equals("1")) {
                    /* If user input is 1,Create object of FirstChoice
                    (Strategy 1
                     */

                    ic = new FirstChoice();
                } else {
                    ic = new SecondChoice();
                }
                context.setChoice(ic);
                context.showChoic(input1,input2);
            }

        }finally {
            in.close();
        }
        System.out.println("End of Strategy Pattern");
    }
}
